const baseHttpurl="http://localhost:8901/"
 //const baseHttpurl="http://localhost:8081/"
const subsysinfo={curid:'',online:false}
import Cookie  from 'js-cookie'
import Vue from "vue"
if(Cookie.get("subsysid")){
    subsysinfo.curid=Cookie.get("subsysid");
}
Date.prototype.dateFormat=function(fmt){
    let o = {   
        "M+" : this.getMonth()+1,                 //月份   
        "d+" : this.getDate(),                    //日   
        "h+" : this.getHours(),                   //小时   
        "m+" : this.getMinutes(),                 //分   
        "s+" : this.getSeconds(),                 //秒   
        "q+" : Math.floor((this.getMonth()+3)/3), //季度   
        "S"  : this.getMilliseconds()             //毫秒   
      };   
      if(/(y+)/.test(fmt))   
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
      for(let k in o)   
        if(new RegExp("("+ k +")").test(fmt))   
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));   
      return fmt;   
}
String.prototype.format=function(...args){
    
    let result = this;
    if (args.length > 0) {
        if (args.length == 1 && typeof (args[0]) == "object") {
            args=args[0];
            for (let key in args) {
                if (args[key] != undefined) {
                    let reg = new RegExp("({" + key + "})", "g");
                    result = result.replace(reg, args[key]);
                }
            }
        }
        else {
            for (let i = 0; i < args.length; i++) {
                if (args[i] != undefined) {
                    //let reg = new RegExp("({[" + i + "]})", "g");//这个在索引大于9时会有问题，谢谢何以笙箫的指出
                    let reg = new RegExp("({)" + i + "(})", "g");
                    result = result.replace(reg, args[i]);
                }
            }
        }
    }
    return result;

}
String.format=function(){
    if(arguments==0)return undefined
    if(arguments.length==1)return arguments[0];
    let args=[],str=arguments[0];
    for(let i=1;i<arguments.length;i++){
        args.push(arguments[i])
    }
    return str.format(...args)
}
function mergeJSON(minor, main) {
    for(let key in minor) {
        if(main[key] === undefined) { // 不冲突的，直接赋值 
            main[key] = minor[key];
            continue;
        }
        // 冲突了，如果是Object，看看有么有不冲突的属性
        // 不是Object 则以（minor）为准为主，
        // console.log(key)
        if(isJSON(minor[key])||isArray(minor[key])) { // args.callee 递归调用，并且与函数名解耦 
            //args.callee(minor[key], main[key]);
            mergeJSON(minor[key], main[key]);
        }else{
            main[key] = minor[key];
        }
    }
    return main;
}

function isJSON(target) {
    
    return typeof target == "object" && target.constructor == Object;
}

function isArray(o) {
    return Object.prototype.toString.call(o) == '[object Array]';
}
function bkapply(){
//console.log(args)
if(arguments.length==0)return{};
let args=[];
for(let s=0;s<arguments.length;s++){
    if(arguments[s])args.push(arguments[s]);
  }
  if(args.length==1)return args[0];
  if(args.length==2)
  return mergeJSON(args[0],args[1]);
  let tempobj=mergeJSON(args[1],args[0]);
  //console.log(tempobj)
  for(let i=2;i<=args.length;i++){
      tempobj=mergeJSON(args[i],tempobj);
  }
  return tempobj;
}
Vue.prototype.bkapply=bkapply
export default{
    baseHttpurl
    ,subsysinfo
}